package homework.one;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class No_1 {

    public static void show(Object obj){
        System.out.println(obj);
    }

    public static void write(FileOutputStream fos,String s){
        byte[] arr = s.getBytes();
        try {
            fos.write(arr);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void read(FileInputStream fis){
        try{
            int len = 0;
            byte [] b = new byte[fis.available()];
            while ((len = fis.read(b)) != -1){
                show(new String(b));
            }
        }catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fis.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {

        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(new File("test.txt"), true);
            fis = new FileInputStream("test.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
        write(fos, "Hello World");
        read(fis);

    }


}
